package com.hollysys.spark

import org.apache.spark.sql.SparkSession

object flatmap {
  def main(args: Array[String]): Unit = {
    val spark = SparkSession
      .builder() //创建Spark会话
      .appName("Spark SQL basic example") //设置会话名称
      .master("local") //设置本地模式
      .getOrCreate() //创建会话变量
    val rdd = spark.sparkContext.parallelize(Seq("hello!spark", "hello!hadoop"))
    import spark.implicits._
    val df = rdd.toDF("id")
    val x = df.flatMap(x => x.toString().split("!")).collect()
    println(x.mkString("Array(", ", ", ")"))
  }
}
